#ifndef HELMETOUTPUTS_H
#define HELMETOUTPUTS_H

#include "HelmetSystemConfig.h"

/**************************************************************************************
	Global Variables
**************************************************************************************/

/**************************************************************************************
	Definitions
**************************************************************************************/
// 5V/12V supply enable/disable
#define PORTA_5V_SUPP_MASK		( BIT_6 )
#define PORTA_12V_SUPP_MASK		( BIT_7 )
#define PORTA_POWER_SUPP_MASK	( PORTA_5V_SUPP_MASK | PORTA_12V_SUPP_MASK )
#define ConfigPowerSuppEnDis()	mPORTASetPinsDigitalOut( PORTA_POWER_SUPP_MASK )
#define Enable5V()				mPORTASetBits( PORTA_5V_SUPP_MASK )
#define Disable5V()				mPORTAClearBits( PORTA_5V_SUPP_MASK )
#define Enable12V()				mPORTASetBits( PORTA_12V_SUPP_MASK )
#define Disable12V()			mPORTAClearBits( PORTA_12V_SUPP_MASK )

// Projector
#define PORTB_PROJ_SW_MASK			( BIT_6 )
#define ConfigProjectorSwitch()		mPORTBSetPinsDigitalOut( PORTB_PROJ_SW_MASK )
#define ProjectorSwitchThrow()		mPORTBSetBits( PORTB_PROJ_SW_MASK )
#define ProjectorSwitchUnThrow()	mPORTBClearBits( PORTB_PROJ_SW_MASK )
#define ProjectorOnOff()			unsigned int _i;\
									ProjectorSwitchThrow();\
									_i=8000000;\
									while( _i>0 ) _i--;\
									ProjectorSwitchUnThrow()

// Cooling Fans
#define PORTD_FAN_MASK	( BIT_15 )
#define ConfigFans()	mPORTDSetPinsDigitalOut( PORTD_FAN_MASK )
#define FansOn()		mPORTDSetBits( PORTD_FAN_MASK )
#define FansOff()		mPORTDClearBits( PORTD_FAN_MASK )

// Button Pad LEDs
#define PORTC_BUTTON_LED_MASK	( BIT_2 )
#define ConfigButtonLEDs()		mPORTCSetPinsDigitalOut( PORTC_BUTTON_LED_MASK )
#define ButtonLEDsOn()			mPORTCSetBits( PORTC_BUTTON_LED_MASK )
#define ButtonLEDsOff()			mPORTCClearBits( PORTC_BUTTON_LED_MASK )

// Vibration Motor
#define PORTF_VIB_MOTOR_MASK	( BIT_3 )
#define ConfigVibMotor()		mPORTFSetPinsDigitalOut( PORTF_VIB_MOTOR_MASK )
#define VibMotorOn()			mPORTFSetBits( PORTF_VIB_MOTOR_MASK )
#define VibMotorOff()			mPORTFClearBits( PORTF_VIB_MOTOR_MASK )

// Peripheral Enable/Disable
// GPS
#define PORTD_GPS_STBY_MASK		( BIT_14 )
#define ConfigGPSSlp()			mPORTDSetPinsDigitalOut( PORTD_GPS_STBY_MASK )
#define GPSRun()				mPORTDSetBits( PORTD_GPS_STBY_MASK )
#define GPSSleep()				mPORTDClearBits( PORTD_GPS_STBY_MASK )
// Accelerometer
#define PORTC_ACCEL_SLP_MASK	( BIT_3 )
#define ConfigAccelSlp()		mPORTCSetPinsDigitalOut( PORTC_ACCEL_SLP_MASK )
#define AccelRun()				mPORTCSetBits( PORTC_ACCEL_SLP_MASK )
#define AccelSleep()			mPORTCClearBits( PORTC_ACCEL_SLP_MASK )


/**************************************************************************************
	Function Prototypes
**************************************************************************************/
void ConfigAllOutputs(void);

/**************************************************************************************
	Functions
**************************************************************************************/
void ConfigAllOutputs() {
	// Config Power supply enable/disables ( initially: 12v off, 5v off )
	ConfigPowerSuppEnDis();
	Disable5V();
	Disable12V();
	
	// Config projector switch
	ConfigProjectorSwitch();
	
	// Config fan outputs (off state initially)
	ConfigFans();
	FansOff();
	
	// Config Button Pad LEDs + Vibration motor (off state initially)
	ConfigButtonLEDs();
	ButtonLEDsOff();
	ConfigVibMotor();
	VibMotorOff();
	
	// Config Peripheral EN/DIS-ables (run mode initially)
	ConfigGPSSlp();
	GPSRun();
	ConfigAccelSlp();
	AccelRun();
}	

/**************************************************************************************
	Interrupt handling routines
**************************************************************************************/
// Note: Priority 1 (lowest) to 7 (highest)

#endif